package org.example.blogserver.controller;

import org.example.blogserver.service.ArticleService;
import org.example.blogserver.service.CommentsService;
import org.example.blogserver.vo.Result;
import org.example.blogserver.vo.params.CommentParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("read-note")
public class ReadNoteController {
    @Autowired
    private CommentsService commentsService;
    @Autowired
    private ArticleService articleService;
    @GetMapping("/read-comments")
    public Result findCommentsVoByArticleId(@RequestParam Long id){
        return commentsService.findCommentsVoByArticleId(id);
    }

    @GetMapping("/get-note")
    public Result findArticleVoById(@RequestParam Long id){
        articleService.addView(id);
        return articleService.findArticleVoById(id);
    }
    @PostMapping("/delete-comment")
    public Result deleteArticleById(@RequestParam Long id){
        return commentsService.deleteCommentById(id);
    }
    @PostMapping("/like")
    public Result addLike(@RequestParam Long id){
        return articleService.addLike(id);
    }
    @PostMapping("/comment")
    public Result addLike(@RequestBody CommentParam commentParam,@RequestHeader String token){
        return commentsService.addComment(token,commentParam);
    }
}
